// Schedule type using discriminated union (F#)
open System;;

type Schedule = 
	| Never
	| Once of DateTime
	| Repeatedly of DateTime * TimeSpan
;;

let tomorrow = DateTime.Now.AddDays(1.0);;
let noon = new DateTime(2012,8,1,12,0,0);;
let daySpan = new TimeSpan(24,0,0);;

let schedule1 = Never;;
let schedule2 = Once(tomorrow);;
let schedule3 = Repeatedly(noon, daySpan);;

let occursNextWeek(schedule) = 
	let isNextWeekDate dt = 
		dt > DateTime.Now && dt < DateTime.Now.AddDays(7.0)
	
	match schedule with
		| Never -> false
		| Once(dt) -> isNextWeekDate(dt)
		| Repeatedly(dt, ts) ->
			let q = (DateTime.Now - dt).TotalSeconds / ts.TotalSeconds
			let q = max q 0.0
			let next = dt.AddSeconds(ts.TotalSeconds * (Math.Floor(q) + 1.0))
			isNextWeekDate(next)
			
occursNextWeek(Once(DateTime.Now.AddDays(5.0)))

open System;;

let readInput() = 
	let s = Console.ReadLine()
	let (succ, num) = Int32.TryParse(s) 
	if (succ) then
		Some(num)
	else
		None;;

let testInput() = 
	let inp = readInput()
	match inp with 
	| Some(v) ->
		printfn "You entered: %d" v
	| None ->
		printfn "Incorrect Input!";;

testInput()
42
